<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<!-- Set render engine for 360 browser -->
	<meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- HTML5 shim for IE8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->

	<link href="/public/simpleboot/themes/<?php echo C('SP_ADMIN_STYLE');?>/theme.min.css" rel="stylesheet">
    <link href="/public/simpleboot/css/simplebootadmin.css" rel="stylesheet">
    <link href="/public/js/artDialog/skins/default.css" rel="stylesheet" />
    <link href="/public/simpleboot/font-awesome/4.4.0/css/font-awesome.min.css"  rel="stylesheet" type="text/css">
    <style>
		.length_3{width: 180px;}
		form .input-order{margin-bottom: 0px;padding:3px;width:40px;}
		.table-actions{margin-top: 5px; margin-bottom: 5px;padding:0px;}
		.table-list{margin-bottom: 0px;}
	</style>
	<!--[if IE 7]>
	<link rel="stylesheet" href="/public/simpleboot/font-awesome/4.4.0/css/font-awesome-ie7.min.css">
	<![endif]-->
<script type="text/javascript">
//全局变量
var GV = {
    DIMAUB: "/",
    JS_ROOT: "public/js/",
    TOKEN: ""
};
document.domain = "xinhuiwen.com";
</script>
<!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/public/js/jquery.js"></script>
    <script src="/public/js/wind.js"></script>
    <script src="/public/js/publish.js"></script>

    <script src="/public/simpleboot/bootstrap/js/bootstrap.min.js"></script>
<?php if(APP_DEBUG): ?><style>
		#think_page_trace_open{
			z-index:9999;
		}
	</style><?php endif; ?>
</head>
<style>
    .input_edit{
        width:120px;}
</style>
<body>
<div class="wrap js-check-wrap">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="<?php echo U('NewsSet/defaultIndex');?>">栏目列表</a></li>
            <?php if($status == 1): ?><li><a href="<?php echo U('NewsSet/add');?>">添加栏目</a></li><?php endif; ?>
        </ul>
        <form class="form-horizontal js-ajax-form" action="<?php echo U('NewsSet/defaultIndex');?>" method="post">
            <table class="table table-hover table-bordered table-list">
                <?php if($status == 1): ?><thead>
                <tr>
                    <th width="80">序号</th>
                    <th width="220">栏目名称</th>
                    <th width="220">权重</th>
                    <th width="700">管理员</th>
                    <th>操作</th>
                </tr>
                </thead>
                <!--显示全部栏目列表 可操作-->
                    <?php if(is_array($data)): foreach($data as $key=>$vo): ?><p style="display: none;" id="dis_column_name"><?php echo ($vo["name"]); ?></p>
                        <p style="display: none;" id="dis_weight"><?php echo ($vo["weight"]); ?></p>
                        <p style="display: none;" id="dis_username"><?php echo ($vo["user_login"]); ?></p>
                        <tr>
                            <td>
                                <?php echo ($vo["column_id"]); ?>
                            </td>
                            <td id="column_id">
                                <input name="<?php echo ($vo["column_id"]); ?>" disabled="disabled" type="text" size="3" value="<?php echo ($vo["name"]); ?>" id="input-column-<?php echo ($vo["column_id"]); ?>" class="input_edit">
                                <a style="float: right;" id="edit_column-<?php echo ($vo["column_id"]); ?>" href="javascript:void(0)" onclick="edit_column('column_id','<?php echo ($vo["column_id"]); ?>')" class="edit_sub">修改</a>
                            </td>
                            <td>
                                <input name="<?php echo ($vo["weight"]); ?>" disabled="disabled" type="text" size="3" value="<?php echo ($vo["weight"]); ?>" id="input-weight-<?php echo ($vo["column_id"]); ?>" class="input_edit">
                                <a style="float: right;"  id="edit_weight-<?php echo ($vo["column_id"]); ?>" href="javascript:void(0)" onclick="edit_column('weight','<?php echo ($vo["column_id"]); ?>')" class="edit_sub">修改</a>
                            </td>
                            <td style="word-wrap:break-word;word-break:break-all;">
                                <?php if($vo["type"] == 2): echo ($name); ?>
                                <?php else: ?>
                                    <?php echo ($vo["usernames"]); endif; ?>


                                <?php if($vo["type"] != 2): ?><a style="float:right;"  class="btn btn-primary"  onclick="edit_admin('<?php echo ($vo["column_id"]); ?>','<?php echo ($vo["admin_ids"]); ?>','<?php echo ($vo["usernames"]); ?>')">修改</a><?php endif; ?>
                            </td>
                            <td>
                                <a href='<?php echo U("Admin/NewsSet/Delete",array("id"=>$vo["column_id"]));?>' class="js-ajax-delete" data-msg="确定要删除此栏目吗？">删除</a>
                                <?php if($vo["type"] != 2): ?><a href="<?php echo U('News/index',array('column_id'=>$vo['column_id']));?>" style="margin-left: 20px;">进入文章列表</a>

                                    <a onclick="edit_liverole('<?php echo ($vo["column_id"]); ?>','<?php echo ($vo["admin_ids"]); ?>','<?php echo ($vo["usernames"]); ?>','<?php echo ($vo["live_status"]); ?>')" style="margin-left: 25px;">直播权限设置</a><?php endif; ?>

                            </td>
                        </tr><?php endforeach; endif; ?>
                    <?php else: ?>
                    <!-- 显示有权限的 可操作栏目 -->
                    <?php if(is_array($data)): foreach($data as $key=>$vo): if($vo['column_id']){ $column = "column_id"; $column_val = $vo['column_id']; }else{ $column = "area_id";$column_val = $vo['area_id']; }?>
                        <tr>
                        <td>
                            <a href="<?php echo U('News/index',array($column=>$column_val));?>"><?php echo ($vo["name"]); ?></a>
                        </td>
                        </tr><?php endforeach; endif; endif; ?>

            </table>
        </form>
        <div class="pagination"><?php echo ($page); ?></div>
    </div>

</div>
<script src="/public/js/common.js"></script>
<script src="/public/js/layer/layer.js"></script>
<script>
    function edit_admin(column_id,admin_ids,usernames){
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '修改管理员',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['600px', '300px'],
            content: "<?php echo U('Admin/NewsSet/editAdmin')?>"+'&column_id='+column_id+'&admin_ids='+admin_ids+'&usernames='+usernames,
            end: function(){
                location.reload();
            }
        });
    }
    function edit_column(type,column_id){
        var edit_column;
        var column_befor;
        var column;
        var now_input_type;
        var now_edit_type;
        if(type == "column_id"){
            edit_column = $("#edit_column-"+column_id).html();
            column_befor = $("#dis_column_name").html();   //原栏目名
            column  = $("#input-column-"+column_id).val(); //现栏目名
            now_input_type = $("#input-column-" + column_id); //栏目 ID
            now_edit_type  = $("#edit_column-" + column_id);  //修改 按钮ID
        } else if(type == "weight"){
            edit_column = $("#edit_weight-" +column_id).html();
            column_befor = $("#dis_weight").html();        //原权重值
            column  = $("#input-weight-" +column_id).val(); //现权重值
            now_input_type = $("#input-weight-" + column_id); //权重 ID
            now_edit_type  = $("#edit_weight-" + column_id);  //修改 按钮ID
        }
        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                if(type == "column_id"){
                    $.ajax({
                        type:"post",
                        async:false,
                        url:"<?php echo U('Admin/Movement/filter_words');?>",
                        data:'name='+column,
                        dataType:"text",
                        success:function(data){
                            if(data){
                                if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
                                    flag= true;
                                    return true;
                                }else{
                                    flag= false;
                                    return false;
                                }
                            }else{
                                flag = true;
                                return true;
                            }
                        }
                    });
                    if(flag == false){
                        return false;
                    }
                }
                $.post("<?php echo U('NewsSet/Edit');?>", {type: type, id: column_id, val: column},
                    function (result) {
                        if (result == 1) {
                            now_input_type.attr("disabled", "disabled");
                            now_edit_type.html("修改");
                            location.reload();
                        }else{
                            alert("异常!");
                        }
                    }
                );
            }
        }
    };

    function edit_liverole(column_id,admin_ids,usernames,live_status){
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '直播权限设置',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['700px', '300px'],
            content: "<?php echo U('Admin/NewsSet/editliverole')?>"+'&column_id='+column_id+'&admin_ids='+admin_ids+'&usernames='+usernames+'&live_status='+live_status+'&type='+0,
            end: function(){
                location.reload();
            }
        });
    }
</script>

</body>
</html>